<template>
<div class="header">
  <div class="logo">LC Jumpserver</div>
  <div class="user-info">
    <el-dropdown trigger="click" @command="handleCommand">
      <span class="el-dropdown-link">
                    <img class="user-logo" src="../../../static/img/img.jpg">
                    {{ username }} {{ roles }}
                </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="loginout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
  <div class="search_bar">
    <el-input v-model="input" placeholder="请输入查找内容"></el-input>
  </div>
</div>
</template>
<script>
import Vue from 'vue'
export default {
  data() {
    return {
      name: 'leo_chan',
      input: ''
    }
  },
  computed: {
    username() {
      let username = localStorage.getItem('username');
      //let username = Vue.prototype.store.getters.curr_user;
      return username && username != "" ? username : this.name;
    },
    roles() {
      let roles = localStorage.getItem('roles');
      //let roles = Vue.prototype.$store.state.roles;
      console.log('roles:' + roles);
      return roles;
    }
  },
  methods: {
    handleCommand(command) {
      if (command == 'loginout') {
        localStorage.removeItem('username')
        //localStorage.removeItem('roles')
        localStorage.removeItem('token')

        Vue.prototype.store.dispatch("resetUser");
        Vue.prototype.store.dispatch("resetToken");
        this.$router.push('/login');
      }
    }
  }
}
</script>
<style scoped>
.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 70px;
  font-size: 22px;
  line-height: 70px;
  color: #fff;
}

.header .logo {
  float: left;
  width: 250px;
  text-align: center;
}

.search_bar {
  float: right;
  width: 350px;
  padding-right: 50px;
  font-size: 16px;
}

.user-info {
  float: right;
  padding-right: 50px;
  font-size: 16px;
  color: #fff;
}

.user-info .el-dropdown-link {
  position: relative;
  display: inline-block;
  padding-left: 50px;
  color: #fff;
  cursor: pointer;
  vertical-align: middle;
}

.user-info .user-logo {
  position: absolute;
  left: 0;
  top: 15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.el-dropdown-menu__item {
  text-align: center;
}
</style>
